package com.whnk.web.controller.pm;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.whnk.common.annotation.Log;
import com.whnk.common.base.AjaxResult;
import com.whnk.common.enums.BusinessType;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.pm.domain.CtrInfo;
import com.whnk.pm.service.ICtrInfoService;

/**
 * 订单基本 信息操作处理
 * 
 * @author whwhnk
 * @date 2019-07-15
 */
@Controller
@RequestMapping("/pm/ctrInfo")
public class CtrInfoController extends BaseController
{
    private String prefix = "pm/ctrInfo";
	
	@Autowired
	private ICtrInfoService ctrInfoService;
	
	@RequiresPermissions("pm:ctrInfo:view")
	@GetMapping()
	public String ctrInfo()
	{
	    return prefix + "/ctrInfo";
	}
	
	/**
	 * 查询订单基本列表
	 */
	@RequiresPermissions("pm:ctrInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(CtrInfo ctrInfo)
	{
		startPage();
        List<CtrInfo> list = ctrInfoService.selectCtrInfoList(ctrInfo);
		return getDataTable(list);
	}
	
	/**
	 * 新增订单基本
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存订单基本
	 */
	@RequiresPermissions("pm:ctrInfo:add")
	@Log(title = "订单基本", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(CtrInfo ctrInfo)
	{		
		return toAjax(ctrInfoService.insertCtrInfo(ctrInfo));
	}

	/**
	 * 修改订单基本
	 */
	@GetMapping("/edit/{ctrId}")
	public String edit(@PathVariable("ctrId") Integer ctrId, ModelMap mmap)
	{
		CtrInfo ctrInfo = ctrInfoService.selectCtrInfoById(ctrId);
		mmap.put("ctrInfo", ctrInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存订单基本
	 */
	@RequiresPermissions("pm:ctrInfo:edit")
	@Log(title = "订单基本", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(CtrInfo ctrInfo)
	{		
		return toAjax(ctrInfoService.updateCtrInfo(ctrInfo));
	}
	
	/**
	 * 删除订单基本
	 */
	@RequiresPermissions("pm:ctrInfo:remove")
	@Log(title = "订单基本", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(ctrInfoService.deleteCtrInfoByIds(ids));
	}
	
	/**
	 * 更新订单明细
	 * 
	 * @param ctrId
	 * @param mmap
	 * @return
	 */
	@GetMapping("/upWl/{ctrId}")
    public String upEdu(@PathVariable("ctrId") Integer ctrId, ModelMap mmap)
    {
		CtrInfo ctrInfo = ctrInfoService.selectCtrInfoById(ctrId);
		mmap.put("ctrInfo", ctrInfo);
        return "pm/ctrWlInfo/ctrWlInfo";
    }
	
	/**
	 * 更新人员名单
	 * 
	 * @param ctrId
	 * @param mmap
	 * @return
	 */
	@GetMapping("/upNmList/{ctrId}")
    public String upNmList(@PathVariable("ctrId") Integer ctrId, ModelMap mmap)
    {
		CtrInfo ctrInfo = ctrInfoService.selectCtrInfoById(ctrId);
		mmap.put("ctrInfo", ctrInfo);
        return "pm/ctrNmList/ctrNmList";
    }
}
